﻿using Md.Api.Model;
using Md.Api.Model.Manage.SysConfig.Request;
using Md.Api.Service.Manage.SysConfig;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 系统参数配置
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/system/config")]
public class SysConfigController : ControllerBase
{
    /// <summary>
    /// 通过配置编号删除系统配置服务
    /// </summary>
    public DeleteSysConfigByConfigIdService deleteSysConfigByConfigIdService { get; set; }
    /// <summary>
    /// 通过配置编号删除系统配置
    /// </summary>
    /// <param name="configIds">配置编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{configIds}")]
    public async Task<ResponseMessageModel> DeleteSysConfigByConfigId(string configIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteSysConfigByConfigIdModel();

        model.ConfigIds = configIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteSysConfigByConfigIdService.Execute(model));
    }

    /// <summary>
    /// 添加系统配置服务
    /// </summary>
    public InsertSysConfigService insertSysConfigService { get; set; }
    /// <summary>
    /// 添加系统配置
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertSysConfig([FromBody] RequestInsertSysConfigModel model)
    {
        return await Task.Run(() => insertSysConfigService.Execute(model));
    }

    /// <summary>
    /// 通过配置编号更新系统配置服务
    /// </summary>
    public UpdateSysConfigByConfigIdService updateSysConfigByConfigIdService { get; set; }
    /// <summary>
    /// 通过配置编号更新系统配置
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateSysConfigByConfigId([FromBody] RequestUpdateSysConfigByConfigIdModel model)
    {
        return await Task.Run(() => updateSysConfigByConfigIdService.Execute(model));
    }

    /// <summary>
    /// 通过配置编号获取系统配置服务
    /// </summary>
    public GetSysConfigByConfigIdService getSysConfigByConfigIdService { get; set; }
    /// <summary>
    /// 通过配置编号获取系统配置
    /// </summary>
    /// <param name="configId">配置编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{configId}")]
    public async Task<ResponseMessageModel> GetSysConfigByConfigId(int configId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysConfigByConfigIdModel();

        model.ConfigId = configId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysConfigByConfigIdService.Execute(model));
    }

    /// <summary>
    /// 通过配置KEY获取系统配置服务
    /// </summary>
    public GetSysConfigByConfigKeyService getSysConfigByConfigKeyService { get; set; }
    /// <summary>
    /// 通过配置KEY获取系统配置
    /// </summary>
    /// <param name="configKey">配置KEY</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("key/{configKey}"), HttpGet]
    public async Task<ResponseMessageModel> GetSysConfigByConfigKey(string configKey, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysConfigByConfigKeyModel();

        model.ConfigKey = configKey;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysConfigByConfigKeyService.Execute(model));
    }

    /// <summary>
    /// 获取系统配置列表服务
    /// </summary>
    public GetSysConfigListService getSysConfigListService { get; set; }
    /// <summary>
    /// 获取系统配置列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetSysConfigList([FromBody] RequestGetSysConfigListModel model)
    {
        return await Task.Run(() => getSysConfigListService.Execute(model));
    }

    /// <summary>
    /// 分页获取系统配置列表服务
    /// </summary>
    public GetSysConfigPageListService getSysConfigPageListService { get; set; }
    /// <summary>
    /// 分页获取系统配置列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetSysPostPagetList([FromBody] RequestGetSysConfigPageListModel model)
    {
        return await Task.Run(() => getSysConfigPageListService.Execute(model));
    }
}

